package com.example.zhihuibj.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * Adapter
 * @author QingZhu
 *
 * @param <T> 
 */
public abstract class CommonAdapter<T> extends BaseAdapter{

	protected List<T> mDatas;
	protected Context mContext;
	protected LayoutInflater mInflater;
	protected int mLayoutId;
	
	public List<T> getDatas() {
		return mDatas;
	}
	
	public void setDatas(List<T> list){
		this.mDatas = list;
	}

	protected CommonAdapter(Context context, List<T> list, int layoutId){
		mDatas = list;
		mContext = context;
		mInflater = LayoutInflater.from(context);
		mLayoutId = layoutId;
	}
	
	@Override
	public int getCount() {
		return mDatas.size();
	}

	@Override
	public T getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	protected abstract void setHolder(ViewHolder holder, T bean, int position);
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		ViewHolder holder = ViewHolder.get(mContext, convertView, position, parent, mLayoutId);
		
		setHolder(holder, mDatas.get(position), position);
		
		return holder.getConvertView();
	}
}
